#!/usr/bin/python
# -*- coding: utf-8 -*-



import os
import sys
from PyQt4 import QtCore, QtGui
from Main import *
class Page6(object):
    def __init__(self,session):
		self.session=session
		self.app = QtGui.QApplication(sys.argv)
		self.window=QtGui.QDialog()
                self.retour=0
                self.parametre={}                                                  
                self.config={}



    def suivant(self):
       


       if self.comboBox_choix.currentText() == "udp":
         file=open("dicoiperfudp",'w')
         file.write("\nserveur:"+self.lineEdit_IP_2.displayText())
         file.write("\nmode:udp")
         file.write("\nintervalle:"+str(int(self.spinBox_intervalle_udp.value())))
         file.write("\nduree:"+str(int(self.doubleSpinBox_duree_udp.value())))
         file.write("\ndebit:"+str(self.lineEdit_max_udp.displayText()))
         file.close()
         file=open("dicocampagne",'a')
         file.write("\nmodeiperf:udp")
         file.close()
         
       if self.comboBox_choix.currentText() == "tcp":
         file=open("dicoiperftcp",'w')
         file.write("\nserveur:"+self.lineEdit_IP_2.displayText())
         file.write("\nmode:tcp")
         file.write("\nintervalle:"+str(int(self.doubleSpinBox_intervalle_tcp.value())))
         file.write("\nduree:"+str(int(self.doubleSpinBox_duree_tcp.value())))
         file.close()
         file=open("dicocampagne",'a')
         file.write("\nmodeiperf:tcp")
         file.close()

       if self.comboBox_choix.currentText() == "tcp & udp":

         file=open("dicoiperfudp",'w')
         file.write("\nserveur:"+self.lineEdit_IP_2.displayText())
         file.write("\nmode:udp")
         file.write("\nintervalle:"+str(int(self.spinBox_intervalle_udp.value())))
         file.write("\nduree:"+str(int(self.doubleSpinBox_duree_udp.value())))
         file.write("\ndebit:"+str(self.lineEdit_max_udp.displayText()))
         file.close()
         file=open("dicoiperftcp",'w')
         file.write("\nserveur:"+self.lineEdit_IP_2.displayText())
         file.write("\nmode:tcp")
         file.write("\nintervalle:"+str(int(self.doubleSpinBox_intervalle_tcp.value())))
         file.write("\nduree:"+str(int(self.doubleSpinBox_duree_tcp.value())))
         file.close()
         file=open("dicocampagne",'a')
         file.write("\nmodeiperf:tcp&udp")
         file.close()

     


       self.window.close()
       obj7=Main()
       obj7.func7(self.config)
       

   

    def choix(self):

      if self.comboBox_choix.currentText() == "tcp":
             self.lineEdit_TCP.setVisible(True)
             self.lineEdit_duree_tcp.setVisible(True)
             self.lineEdit_intervalle_tcp.setVisible(True)
             self.doubleSpinBox_duree_tcp.setVisible(True)
             self.doubleSpinBox_intervalle_tcp.setVisible(True)
             self.comboBox_taille_tcp.setVisible(True)
             self.lineEdit_taille_tcp.setVisible(True)


             self.lineEdit_UDP.setVisible(False)
             self.lineEdit_duree_udp.setVisible(False)
             self.lineEdit_intervalle_udp.setVisible(False)
             self.doubleSpinBox_duree_udp.setVisible(False)
             self.spinBox_intervalle_udp.setVisible(False)
         #   self.lineEdit_taille_udp.setVisible(True)
             self.lineEdit_max_udp.setVisible(False)   
             self.lineEdit_duree_udp.setVisible(False)     
             self.lineEdit_debit_udp.setVisible(False)

      if self.comboBox_choix.currentText() == "udp":       
             self.lineEdit_UDP.setVisible(True)
             self.lineEdit_duree_udp.setVisible(True)
             self.lineEdit_intervalle_udp.setVisible(True)
             self.doubleSpinBox_duree_udp.setVisible(True)
             self.spinBox_intervalle_udp.setVisible(True)
         #   self.lineEdit_taille_udp.setVisible(True)
             self.lineEdit_max_udp.setVisible(True)   
             self.lineEdit_duree_udp.setVisible(True)     
             self.lineEdit_debit_udp.setVisible(True)

             self.lineEdit_TCP.setVisible(False)
             self.lineEdit_duree_tcp.setVisible(False)
             self.lineEdit_intervalle_tcp.setVisible(False)
             self.doubleSpinBox_duree_tcp.setVisible(False)
             self.doubleSpinBox_intervalle_tcp.setVisible(False)
             self.comboBox_taille_tcp.setVisible(False)
             self.lineEdit_taille_tcp.setVisible(False)
             
      if self.comboBox_choix.currentText() == "tcp & udp":    
             self.lineEdit_UDP.setVisible(True)
             self.lineEdit_duree_udp.setVisible(True)
             self.lineEdit_intervalle_udp.setVisible(True)
             self.doubleSpinBox_duree_udp.setVisible(True)
             self.spinBox_intervalle_udp.setVisible(True)
         #   self.lineEdit_taille_udp.setVisible(True)
             self.lineEdit_max_udp.setVisible(True)   
             self.lineEdit_duree_udp.setVisible(True)     
             self.lineEdit_debit_udp.setVisible(True)

             self.lineEdit_TCP.setVisible(True)
             self.lineEdit_duree_tcp.setVisible(True)
             self.lineEdit_intervalle_tcp.setVisible(True)
             self.doubleSpinBox_duree_tcp.setVisible(True)
             self.doubleSpinBox_intervalle_tcp.setVisible(True)
             self.comboBox_taille_tcp.setVisible(True)
             self.lineEdit_taille_tcp.setVisible(True)




    def affich(self,param):
        #self.parametre=param
	self.setupUi(self.window)
	self.window.show()
        sys.exit(self.app.exec_())

    def precedent(self):
        self.window.close()
        obj5=Main()
        obj5.func5(self.parametre)

    def setupUi(self, Dialog):
        os.system("echo>dicoiperfudp;echo>dicoiperftcp")
        Dialog.setObjectName("Dialog")
        Dialog.resize(1280, 740)
        self.lineEdit_parametres = QtGui.QLineEdit(Dialog)
        self.lineEdit_parametres.setGeometry(QtCore.QRect(160, 20, 991, 66))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(32)
        font.setWeight(50)
        font.setBold(False)
        self.lineEdit_parametres.setFont(font)
        self.lineEdit_parametres.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_parametres.setReadOnly(True)
        self.lineEdit_parametres.setObjectName("lineEdit_parametres")
        self.lineEdit_TCP = QtGui.QLineEdit(Dialog)
        self.lineEdit_TCP.setGeometry(QtCore.QRect(80, 240, 71, 37))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_TCP.setFont(font)
        self.lineEdit_TCP.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_TCP.setReadOnly(True)
        self.lineEdit_TCP.setObjectName("lineEdit_TCP")
        self.lineEdit_TCP.setVisible(False)
        self.lineEdit_UDP = QtGui.QLineEdit(Dialog)
        self.lineEdit_UDP.setGeometry(QtCore.QRect(720, 240, 71, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_UDP.setFont(font)
        self.lineEdit_UDP.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_UDP.setReadOnly(True)
        self.lineEdit_UDP.setObjectName("lineEdit_UDP")
        self.lineEdit_UDP.setVisible(False)
        self.lineEdit_debit_udp = QtGui.QLineEdit(Dialog)
        self.lineEdit_debit_udp.setGeometry(QtCore.QRect(760, 430, 261, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        font.setItalic(False)
        self.lineEdit_debit_udp.setFont(font)
        self.lineEdit_debit_udp.setAutoFillBackground(False)
        self.lineEdit_debit_udp.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_debit_udp.setReadOnly(True)
        self.lineEdit_debit_udp.setObjectName("lineEdit_debit_udp")
        self.lineEdit_debit_udp.setVisible(False)
        self.pushButton_suivant = QtGui.QPushButton(Dialog)
        self.pushButton_suivant.setGeometry(QtCore.QRect(1054, 650, 151, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(12)
        self.pushButton_suivant.setFont(font)
        self.pushButton_suivant.setObjectName("pushButton_suivant")
        self.pushButton_annuler = QtGui.QPushButton(Dialog)
        self.pushButton_annuler.setGeometry(QtCore.QRect(760, 650, 105, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(12)
        self.pushButton_annuler.setFont(font)
        self.pushButton_annuler.setObjectName("pushButton_annuler")
        self.lineEdit_duree_tcp = QtGui.QLineEdit(Dialog)
        self.lineEdit_duree_tcp.setGeometry(QtCore.QRect(120, 310, 281, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_duree_tcp.setFont(font)
        self.lineEdit_duree_tcp.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_duree_tcp.setReadOnly(True)
        self.lineEdit_duree_tcp.setObjectName("lineEdit_duree_tcp")
        self.lineEdit_duree_tcp.setVisible(False)
        self.lineEdit_intervalle_tcp = QtGui.QLineEdit(Dialog)
        self.lineEdit_intervalle_tcp.setGeometry(QtCore.QRect(120, 370, 331, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_intervalle_tcp.setFont(font)
        self.lineEdit_intervalle_tcp.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_intervalle_tcp.setReadOnly(True)
        self.lineEdit_intervalle_tcp.setObjectName("lineEdit_intervalle_tcp")
        self.lineEdit_intervalle_tcp.setVisible(False)
        self.lineEdit_duree_udp = QtGui.QLineEdit(Dialog)
        self.lineEdit_duree_udp.setGeometry(QtCore.QRect(760, 310, 291, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_duree_udp.setFont(font)
        self.lineEdit_duree_udp.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_duree_udp.setReadOnly(True)
        self.lineEdit_duree_udp.setObjectName("lineEdit_duree_udp")
        self.lineEdit_duree_udp.setVisible(False)
        self.doubleSpinBox_duree_tcp = QtGui.QDoubleSpinBox(Dialog)
        self.doubleSpinBox_duree_tcp.setGeometry(QtCore.QRect(400, 310, 72, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.doubleSpinBox_duree_tcp.setFont(font)
        self.doubleSpinBox_duree_tcp.setAlignment(QtCore.Qt.AlignCenter)
        self.doubleSpinBox_duree_tcp.setDecimals(0)
        self.doubleSpinBox_duree_tcp.setMinimum(0.0)
        self.doubleSpinBox_duree_tcp.setMaximum(1000.0)
        self.doubleSpinBox_duree_tcp.setSingleStep(10.0)
        self.doubleSpinBox_duree_tcp.setObjectName("doubleSpinBox_duree_tcp")
        self.doubleSpinBox_duree_tcp.setVisible(False)
        self.doubleSpinBox_intervalle_tcp = QtGui.QDoubleSpinBox(Dialog)
        self.doubleSpinBox_intervalle_tcp.setGeometry(QtCore.QRect(450, 370, 72, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.doubleSpinBox_intervalle_tcp.setFont(font)
        self.doubleSpinBox_intervalle_tcp.setAlignment(QtCore.Qt.AlignCenter)
        self.doubleSpinBox_intervalle_tcp.setDecimals(0)
        self.doubleSpinBox_intervalle_tcp.setMinimum(0.0)
        self.doubleSpinBox_intervalle_tcp.setMaximum(1000.0)
        self.doubleSpinBox_intervalle_tcp.setProperty("value", QtCore.QVariant(0.0))
        self.doubleSpinBox_intervalle_tcp.setObjectName("doubleSpinBox_intervalle_tcp")
        self.doubleSpinBox_intervalle_tcp.setVisible(False)
        self.pushButton_precedent = QtGui.QPushButton(Dialog)
        self.pushButton_precedent.setGeometry(QtCore.QRect(880, 650, 171, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(12)
        self.pushButton_precedent.setFont(font)
        self.pushButton_precedent.setObjectName("pushButton_precedent")
        self.doubleSpinBox_duree_udp = QtGui.QDoubleSpinBox(Dialog)
        self.doubleSpinBox_duree_udp.setGeometry(QtCore.QRect(1060, 310, 72, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.doubleSpinBox_duree_udp.setFont(font)
        self.doubleSpinBox_duree_udp.setAlignment(QtCore.Qt.AlignCenter)
        self.doubleSpinBox_duree_udp.setDecimals(0)
        self.doubleSpinBox_duree_udp.setMinimum(0.0)
        self.doubleSpinBox_duree_udp.setMaximum(1000.0)
        self.doubleSpinBox_duree_udp.setSingleStep(10.0)
        self.doubleSpinBox_duree_udp.setObjectName("doubleSpinBox_duree_udp")
        self.doubleSpinBox_duree_udp.setVisible(False)
        self.comboBox_choix = QtGui.QComboBox(Dialog)
        self.comboBox_choix.setGeometry(QtCore.QRect(80, 180, 171, 36))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.comboBox_choix.setFont(font)
        self.comboBox_choix.setObjectName("comboBox_choix")
        self.comboBox_choix.addItem(QtCore.QString())
        self.comboBox_choix.addItem(QtCore.QString())
        self.comboBox_choix.addItem(QtCore.QString())  
        self.comboBox_choix.addItem("tcp & udp")
        self.lineEdit_intervalle_udp = QtGui.QLineEdit(Dialog)
        self.lineEdit_intervalle_udp.setGeometry(QtCore.QRect(760, 370, 321, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_intervalle_udp.setFont(font)
        self.lineEdit_intervalle_udp.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_intervalle_udp.setReadOnly(True)
        self.lineEdit_intervalle_udp.setObjectName("lineEdit_intervalle_udp")
        self.lineEdit_intervalle_udp.setVisible(False)
        self.spinBox_intervalle_udp = QtGui.QSpinBox(Dialog)
        self.spinBox_intervalle_udp.setGeometry(QtCore.QRect(1090, 370, 72, 41))
        
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.spinBox_intervalle_udp.setFont(font)
        self.spinBox_intervalle_udp.setAlignment(QtCore.Qt.AlignCenter)
        self.spinBox_intervalle_udp.setMinimum(0)
        self.spinBox_intervalle_udp.setMaximum(1000)
        self.spinBox_intervalle_udp.setSingleStep(2)
        self.spinBox_intervalle_udp.setObjectName("spinBox_intervalle_udp")
        self.spinBox_intervalle_udp.setVisible(False)
        self.lineEdit_IP = QtGui.QLineEdit(Dialog)
        self.lineEdit_IP.setGeometry(QtCore.QRect(80, 110, 311, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_IP.setFont(font)
        self.lineEdit_IP.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_IP.setReadOnly(True)
        self.lineEdit_IP.setObjectName("lineEdit_IP")
        self.checkBox_max = QtGui.QCheckBox(Dialog)
        self.checkBox_max.setGeometry(QtCore.QRect(1050, 440, 161, 23))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.checkBox_max.setFont(font)
        self.checkBox_max.setObjectName("checkBox_max")
        self.checkBox_max.setVisible(False)
        self.lineEdit_max_udp = QtGui.QLineEdit(Dialog)
        self.lineEdit_max_udp.setGeometry(QtCore.QRect(1050, 470, 151, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_max_udp.setFont(font)
        self.lineEdit_max_udp.setObjectName("lineEdit_max_udp")
        #self.lineEdit_max_udp.setVisible(True)
        self.lineEdit_max_udp.setVisible(False)
        self.lineEdit_taille_tcp = QtGui.QLineEdit(Dialog)
        self.lineEdit_taille_tcp.setGeometry(QtCore.QRect(120, 430, 431, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_taille_tcp.setFont(font)
        self.lineEdit_taille_tcp.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_taille_tcp.setReadOnly(True)
        self.lineEdit_taille_tcp.setObjectName("lineEdit_taille_tcp")
        self.lineEdit_taille_tcp.setVisible(False)
        self.comboBox_taille_tcp = QtGui.QComboBox(Dialog)
        self.comboBox_taille_tcp.setGeometry(QtCore.QRect(560, 430, 91, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        self.comboBox_taille_tcp.setFont(font)
        self.comboBox_taille_tcp.setObjectName("comboBox_taille_tcp")
        self.comboBox_taille_tcp.setVisible(False)
        self.lineEdit_IP_2 = QtGui.QLineEdit(Dialog)
        self.lineEdit_IP_2.setGeometry(QtCore.QRect(430, 110, 211, 41))
        font = QtGui.QFont()
        font.setFamily("Bitstream Charter")
        font.setPointSize(14)
        self.lineEdit_IP_2.setFont(font)
        #self.lineEdit_IP_2.setMaxLength(3)
        self.lineEdit_IP_2.setObjectName("lineEdit_IP_2")
       

        self.retranslateUi(Dialog)
        QtCore.QObject.connect(self.comboBox_choix, QtCore.SIGNAL("activated(QString)"), self.choix)
        
        QtCore.QObject.connect(self.comboBox_taille_tcp, QtCore.SIGNAL("activated(QString)"), Dialog.accept)
        QtCore.QObject.connect(self.pushButton_annuler, QtCore.SIGNAL("clicked()"), Dialog.accept)
        QtCore.QObject.connect(self.pushButton_precedent, QtCore.SIGNAL("clicked()"), self.precedent)
        QtCore.QObject.connect(self.pushButton_suivant, QtCore.SIGNAL("clicked()"), self.suivant)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_parametres.setText(QtGui.QApplication.translate("Dialog", "PARAMETRES DU TEST DE DEBIT", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_TCP.setText(QtGui.QApplication.translate("Dialog", "TCP", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_UDP.setText(QtGui.QApplication.translate("Dialog", "UDP", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_debit_udp.setText(QtGui.QApplication.translate("Dialog", "Debit (en MBits/s) :", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_suivant.setText(QtGui.QApplication.translate("Dialog", "Suivant >>", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_annuler.setText(QtGui.QApplication.translate("Dialog", "Annuler", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_duree_tcp.setText(QtGui.QApplication.translate("Dialog", "Duree du test (en s):", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_intervalle_tcp.setText(QtGui.QApplication.translate("Dialog", "Intervalle de test (en s):", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_duree_udp.setText(QtGui.QApplication.translate("Dialog", "Duree du test (en s) :", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_precedent.setText(QtGui.QApplication.translate("Dialog", "<< Precedent", None, QtGui.QApplication.UnicodeUTF8))
        self.comboBox_choix.setItemText(0, QtGui.QApplication.translate("Dialog", "...", None, QtGui.QApplication.UnicodeUTF8))
        self.comboBox_choix.setItemText(1, QtGui.QApplication.translate("Dialog", "tcp", None, QtGui.QApplication.UnicodeUTF8))
        self.comboBox_choix.setItemText(2, QtGui.QApplication.translate("Dialog", "udp", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_intervalle_udp.setText(QtGui.QApplication.translate("Dialog", "Intervalle du test (en s):", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_IP.setText(QtGui.QApplication.translate("Dialog", "Adresse IP du serveur :", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_max.setText(QtGui.QApplication.translate("Dialog", "Maximum", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_taille_tcp.setText(QtGui.QApplication.translate("Dialog", "Taille de la fenêtre (en Koctets) :", None, QtGui.QApplication.UnicodeUTF8))

